package net.lucamasini.ricette.restlet;

import java.util.logging.Level;

import javax.servlet.ServletContext;

import net.lucamasini.ricette.model.Ricetta;
import net.lucamasini.ricette.server.RicetteServiceServlet;

import org.restlet.resource.ServerResource;

public class RicetteServerResources extends ServerResource implements
		RicetteResources {

	private final RicetteServiceServlet service = new RicetteServiceServlet(){
		private static final long serialVersionUID = 1L;

		@Override
		public ServletContext getServletContext() {
			return (ServletContext)getContext().getAttributes().get("org.restlet.ext.servlet.ServletContext");
		}
	};

	private String id;  
	  
    @Override  
    public void doInit() {  
        this.id = (String) getRequestAttributes().get("id"); 
        getContext().getLogger().log(Level.FINE, id);
    }  
	
	@Override
	public Ricetta retrieve() {

		String stampami = "Resource URI  : " + getReference() + '\n' + "Root URI      : " 
        + getRootRef() + '\n' + "Routed part   : " 
        + getReference().getBaseRef() + '\n' + "Remaining part: " 
        + getReference().getRemainingPart();  
		
		System.out.println(stampami);

		return service.findAllRicette().get(0);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
